package com.neusoft.yuejian_01.activity;

import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.adapter.ActivityAdapter;
import com.neusoft.yuejian_01.base.BaseActivity;
import com.neusoft.yuejian_01.javabean.ActivityBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.model.ActivityModel;

import java.util.List;

public class ActActivity extends BaseActivity implements RetrofitListener{
    private RecyclerView recyclerView;
    private ActivityAdapter adapter;
    private ImageButton button_back;//返回按钮

    protected void initView() {//初始化
        setContentView(R.layout.activity_act);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        button_back = (ImageButton) findViewById(R.id.button_back);
    }
    protected void initEvents() {//点击事件处理
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(ActActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }
    protected void initData() {
        ActivityModel activityModel = new ActivityModel();
        activityModel.activitylist(this);
    }
    @Override
    public void onSuccess(Object object, int flag) {
        List<ActivityBean> activityBean   = (List<ActivityBean>)object;
        adapter = new ActivityAdapter(ActActivity.this,activityBean);
        LinearLayoutManager layoutManager = new LinearLayoutManager(ActActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }
    @Override
    public void onFail() {
        Toast.makeText(this,"fail",Toast.LENGTH_LONG).show();
    }
}